<?php

namespace App\Models;

use App\Http\Constants\Account\CommonCoinReserveCoinLogConstants;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class CommonCoinReserveCoinLog extends Model
{
    use HasFactory;

    protected $appends = ['status_name','child_type_name'];

    protected $table = 'common_coin_reserve_coin_log';


    protected $fillable = [
        'id',
        'coin_id',
        'coin',
        'now_coin',
        'order_no',
        'status',
        'child_type',
        'create_time',
        'update_time',
        'remark',
        'expected_at',
    ];

    protected $casts = [

    ];

    public function CommonCoinCoin()
    {
        return $this->hasOne(CommonCoinCoin::class,'id','coin_id');
    }

    protected function getStatusNameAttribute()
    {
        $attributes = $this->attributes;
        $value = array_key_exists('status', $attributes) ? $attributes['status'] : null;
        if (is_null($value)) return null;
        $map = array_column(CommonCoinReserveCoinLogConstants::COMMONCOIN_STATUS,'label','value');
        return array_key_exists($value,$map)? $map[$value]:null;
    }

    protected function getChildTypeNameAttribute()
    {
        $value = $this->attributes['child_type'];
        $map = array_column(CommonCoinReserveCoinLogConstants::COMMONCOIN_TYPE,'label','value');
        return array_key_exists($value,$map)? $map[$value]:null;
    }

}
